function printMatrix(matrix)
{
    // write code here
    if(matrix === []) return []
    var top = 0
    var bottom = matrix.length - 1
    var left = 0
    var right = matrix[0].length - 1
    var res = []
    while(true){
      for(let i = left ;i <= right;i++){
        res.push(matrix[top][i])
      }
      top++
      if(top>bottom) return res
      for(let i = top ;i <= bottom;i++){
        res.push(matrix[i][right])
      }
      right--
      if(right<left) return res
      for(let i = right ;i >= left;i--){
        res.push(matrix[bottom][i])
      }
      bottom--
      if(top>bottom) return res
      for(let i = bottom ;i >= top;i--){
        res.push(matrix[i][left])
      }
      left++
      if(right<left) return res
    }
}
module.exports = {
    printMatrix : printMatrix
};